<%@page import="com.easyattendance.model.MaterialClass"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import ="com.easyattendance.services.AddMaterialService" %>
<%@ page import ="com.easyattendance.services.AddSubjectService" %>
<%@ page import ="com.easyattendance.model.Material" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Comparator" %>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Teacher - Material Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />

<!-- fooTable Links -->
<link href="../css/footable.core.css" rel="stylesheet" type="text/css" />
<link href="../css/footable.metro.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/public/js/footable.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/public/js/footable.sort.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function () {
		$('.footable').footable();
	});
</script>
</head>


<% String currentUser = (String) session.getAttribute("currentUser");
   AddSubjectService subjectService=new AddSubjectService();
   
    AddMaterialService addMaterialService = new AddMaterialService();	
    //List<Material> MaterialList = new ArrayList<Material>();
    List<MaterialClass> MaterialClassList=new ArrayList<MaterialClass>();   
	MaterialClassList=addMaterialService.listMaterialsByClass(currentUser);
	
   /* Sorting list based on Class id */
	Collections.sort(MaterialClassList,new MaterialClass.SortMaterialByClass());
	   
	MaterialClass tempmaterial = null;
	Iterator MaterialClassItr=null;
	int i=0;					

	AddTeacherService addTeacherService = new AddTeacherService();
	Teacher teacher_role = addTeacherService.getTeacherByEmailId(currentUser);
   
%>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp" />
<jsp:include page="../common/checkTeacherRole.jsp" />

	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">

				<div>
					<form action="<%=request.getContextPath()%>/views/teacher/addMaterial.jsp">
					<% if(teacher_role.isClassTeacher()){ %>
						<input type="submit" value="Add Material" class="button add_button" tabindex="1">
					<% }else{ %>
						<input type="submit" value="Add Material" class="add_button" tabindex="1" disabled="disabled">
					<% } %>
					</form>
				</div>				
				
				<span class="success_msg">${materialDeleted}</span>
				<span class="error_msg">${materialNotDeleted}</span>
				<span class="error_msg">${invalidChoice}</span>

  		<div >
		      <form name="material" action="${pageContext.request.contextPath}/AddMaterialServlet" class="gridview"> 
				<table name="material" id="tbl_material" class="footable metro-attendance">
                <thead>
                <tr>
                    <th data-sort-ignore="true"></th>
                    <th data-toggle="true" data-sort-ignore="true">
                        Material Id
                    </th>
                    <th data-toggle="true"  data-sort-ignore="true">
                        Class Id
                    </th>
                    
                    <th data-toggle="true" data-sort-ignore="true">
                        Subject Name
                    </th>
                    
                    <th data-toggle="true" data-sort-ignore="true">
                        Material Type
                    </th>
           			<!-- <th data-toggle="true" data-sort-ignore="true">
                        Path
                    </th>   --> 
                </tr>
                </thead>
              <tbody>
		
		<%
		    if(MaterialClassList!=null)
		    {
		 		MaterialClassItr = MaterialClassList.iterator();%>
			<% while(MaterialClassItr.hasNext()) { i++;%>
						 <% try {
									tempmaterial = (MaterialClass) MaterialClassItr.next();
								} 
								catch(Exception ex){
									ex.printStackTrace();
								}%> 
								
				<tr>				
					
					<td>
						<input type="checkbox" id="checkbox" name="checkbox<%=i%>" class="chk" value="<%=(i-1)%>">
					</td>
					
					<td data-value="<%=tempmaterial.getMaterial_id() %>">
						<input type="text" id="material_id" name="material_id" value="<%=tempmaterial.getMaterial_id()%>" readonly="readonly" />
					</td>
					
					<td data-value="<%=tempmaterial.getClass_id() %>">
						 <input type="text" id="class_id" name="class_id" value="<%=tempmaterial.getClass_id()%> " readonly="readonly" />	 
					</td>
					
					
					
					<td data-value="<%=subjectService.getSubjectBySubjectId(tempmaterial.getSubject_id()).getSubject_name() %>">
						<input type="text" id="subject_name" name="subject_name" value="<%=subjectService.getSubjectBySubjectId(tempmaterial.getSubject_id()).getSubject_name() %>" readonly="readonly" />		
					</td>
					
					<td data-value="<%=tempmaterial.getMaterial().getMaterial_type() %>">
						<input type="text" id="material_type" name="material_type" value="<%=tempmaterial.getMaterial().getMaterial_type()%>" readonly="readonly" />	
					</td>
					
					<!-- <td data-value="<%--<%=tempmaterial.getMaterial().getPhysical_path() %>">
						<input type="text" id="path<%=i%>" name="path<%=i%>" value="<%=tempmaterial.getMaterial().getPhysical_path()%> --%>" readonly="readonly" />	
					</td>  -->
					
					
				</tr>	
					
						
			<% } %>
		 <% } %>		
	  			
	 </tbody>
   </table>
		
		<!--  Hidden fields -->
		 <input type="hidden" id="action_type" name="action_type" value="delete" /> 
		 <input type="hidden" id="user_type" name="user_type" value="teacher" />
		 <% if(teacher_role.isClassTeacher()){ %>
   		 <input type="submit" id="deleteMaterial" value="Delete Selected Materials" class="button add_button" onclick="return confirm('Are you sure you want to delete?')">
   		 <% }else{ %>
   		 <input type="submit" id="deleteMaterial" value="Delete Selected Materials" class="add_button" disabled="disabled">
   		 <% } %>		
  </form> 
</div>			 			
					
	</div>
</div>					
					
		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" />

			<jsp:include page="teacherMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#materialSettings").addClass("current_page_item");
		});
	</script>

</body>
</html>